/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/24 17:10:51
 */
Ext.define('Monkey.view.permission.GrantPermissionPanel', {
    extend: 'Ext.panel.Panel',

    controller: 'ctrl-grantpermission',
    layout: 'border',
    moduleParam: '',
    moduleValue: '',
    getMenuPermissionURL: '',
    grantRecoveryPermissionURL: '',
    changeTree: false,
    initComponent: function () {
        if (Ext.isEmpty(this.moduleParam)) {
            Ext.raise('moduleParam属性不能为空');
        }
        if (Ext.isEmpty(this.moduleValue)) {
            Ext.raise('moduleValue属性不能为空');
        }
        if (Ext.isEmpty(this.getMenuPermissionURL)) {
            Ext.raise('getMenuPermissionURL属性不能为空');
        }
        if (Ext.isEmpty(this.grantRecoveryPermissionURL)) {
            Ext.raise('grantRecoveryPermissionURL属性不能为空');
        }
        var me = this;
        var resources = Ext.create('Monkey.store.menu.Menu');
        var permission = Ext.create('Monkey.store.BaseStore', {
            model: 'Monkey.model.permission.Permission',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                pageParam: 'page.pn',
                limitParam: 'page.size',
                url: Monkey.URL.SERVER_URL + "/m/permissions.json",
                extraParams: {
                    fields: 'id,name,permission,description'
                },
                reader: {
                    type: 'json',
                    totalProperty: 'data.totalAmount',
                    rootProperty: 'data.elements'
                }
            }
        });
        var menuPanel = {
            title: '菜单资源(<span style="color:red">选择一个</span>)',
            reference: 'menuTreePanel',
            region: 'west',
            width: 220,
            icon: 'resources/icons/16/plugin.png',
            xtype: 'treepanel',
            rootVisible: false,
            animate: true,
            border: false,
            displayField: 'name',
            reserveScrollbar: true,
            useArrows: true,
            store: resources,
            listeners: {
                itemclick: 'selectResource'
            }
        };
        me.items = [menuPanel, {
            region: 'center',
            reference: 'permissionCmp',
            bodyPadding: 1,
            title: '分配权限',
            icon: 'resources/icons/16/lightning.png',
            border: false,
            layout: 'fit',
            items: [{
                border: false,
                xtype: 'itemselector',
                store: permission,
                displayField: 'display',
                valueField: 'id',
                fromTitle: '所有权限',
                toTitle: '已有权限',
                listeners: {
                    change: 'saveMenuPermission'
                }
            }]
        }];
        me.callParent();
    }
});